#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 35;

int n, m;
ll s[N];
ll dp[N][N];
ll root[N][N];
void out(int l, int r) {
  if (l > r) return;
  int i = root[l][r];
  cout << i << ' ';
  out(l, i - 1);
  out(i + 1, r);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> s[i];
  rep(i, 1, n) dp[i][i] = s[i], root[i][i] = i;
  rep(len, 2, n) {
    rep(l, 1, n + 1 - len) {
      int r = l + len - 1;
      ll x = s[l] + dp[l + 1][r];
      ll y = s[r] + dp[l][r - 1];
      if (x >= y)
        dp[l][r] = x, root[l][r] = l;
      else
        dp[l][r] = y, root[l][r] = r;
      rep(i, l + 1, r - 1) {
        ll z = s[i] + dp[l][i - 1] * dp[i + 1][r];
        if (z > dp[l][r]) dp[l][r] = z, root[l][r] = i;
      }
    }
  }
  cout << dp[1][n] << endl;
  out(1, n);
  return 0;
}